package org.oncase.smcase.controller;

import org.oncase.smcase.dao.ActivityDAO;
import org.oncase.smcase.dao.HibernateDAO;
import org.oncase.smcase.dao.ObjectiveDAO;
import org.oncase.smcase.entity.Activity;
import org.oncase.smcase.entity.Objective;
import org.oncase.smcase.exception.ActivityException;
import org.oncase.smcase.exception.BSCException;

public class ActivityControllerImpl extends BSCControllerImpl<Activity> implements ActivityController {
	
	ObjectiveDAO objDAO;

	public ActivityControllerImpl(HibernateDAO<Activity> dao, ObjectiveDAO objDAO) {
		super(dao);
		this.objDAO = objDAO;
	}

	protected ActivityDAO getDAO() {
		return (ActivityDAO) this.getDAO();
	}

	@Override
	public void insert(Activity a, int objId) throws BSCException {
		Objective obj = this.objDAO.findByPK(objId);
		if (obj != null) {
			getDAO().insert(a);
			obj.getActivities().add(a);
		} else {
			throw new ActivityException("The Objective does not exists.");
		}
	}

}
